﻿app.service('icdDicData', function ($http) {
    var apiURL = serverURL + '/icd';
    //var paramCallback = QueryUriParamBuilder.queryParam('callback', 'JSON_CALLBACK').build();

    this.GetAll = function () {
        //return $http.jsonp(apiURL + paramCallback);
        return $http.get(apiURL);
    }

    //this.GetTree = function (systemId) {
    //    var param = (systemId && systemId.length > 0) ? '&key=' + systemId : '';
    //    return $http.get(apiURL + '?format=tree' + param);
    //}

    this.GetByParent = function (pCode, tid) {
        if (pCode == 0 || (pCode && pCode.length > 0)) {
            var param = '?pcode=' + pCode;
            if (tid && tid == 'ICD-9' ? '&tid=nine' : '') {
                param += '&tid=nine';
            }
            return $http.get(apiURL + param);
        } else {
            return null;
        }
    }

    this.GetSynonym = function (sCode) {
        return $http.get(apiURL + '?scode=' + sCode);
    }

    this.GetMapping = function (mCode) {
        return $http.get(apiURL + '?mcode=' + mCode);
    }

    this.Add = function (data) {
        return $http.post(apiURL, data);
    }

    this.Edit = function (data) {
        return $http.put(apiURL, data);
    }

    this.Delete = function (id) {
        var params = QueryUriParamBuilder.queryParam("tid", "del").queryParam("id", id).build();
        //return $http.delete(apiURL + params);
        return $http.get(apiURL + params);
    }
});